import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Manage',
    component:  ()=>import('../views/Manage.vue'),
    redirect:"/home",
    children:[
      {path:'user',name:'用户管理',component:()=>import('../views/User')},
      {path:'home',name:'首页',component:()=>import('../views/Home')},
      {path:'goods',name:'垃圾管理',component:()=>import('../views/goods')},
      {path:'collector',name:'回收员管理',component:()=>import('../views/Collector')},
      {path:'order',name:'订单管理',component:()=>import('../views/Order')}
    ]
  },
  {
    path:'/login',
    name:'Login',
    component: ()=>import('../views/Login')
  },
  {
    path: '/register',
    name:'Register',
    component:()=>import('../views/Register')
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
 localStorage.setItem("pathName",to.name)
  store.commit("setPath")
  next()
})

export default router
